<?php

require_once("database.include.php");

	$userName = $_SESSION['username'];
	$groupName = $_GET['groupName'];
	
	//echo 'user: ' . $userName . ', group: ' . $groupName;
	
	print "Your Group Messages:<br/>";
	print "<form id='groupMessagesForm'><table border=`1` id = 'groupMessagesTable'><tr>
	<th bgcolor=darkgray><font color=white>select</font></th>
	<th bgcolor=darkgray><font color=white>message_id</font></th>
	<th bgcolor=darkgray><font color=white>group_name</font></th>
	<th bgcolor=darkgray><font color=white>user_name</font></th>
	<th bgcolor=darkgray><font color=white>message</font></th>
	<th bgcolor=darkgray><font color=white>retention_mode</font></th>
	<th bgcolor=darkgray><font color=white>expiration_date</font></th></tr>";
	
	
    $sql = ' SELECT `message`.* '
		. ' FROM `group_user` '
		. ' INNER JOIN `group` on `group`.name = `group_user`.group_name '
		. ' INNER JOIN `message` on `message`.group_name = `group_user`.group_name '
		. ' WHERE `group_user`.user_name = ' . "'" . $userName . "' "
		. ' AND `group`.name = ' . "'" . $groupName . "'";
		
	//echo $sql;
		
	$rowCount = 1;
	
    foreach ($conn->query($sql) as $row) {
    	print "\n<tr>";
		if ( $rowCount == 1) {
			print "<td><input type='radio' name='rowNumber' value='" . $rowCount . "' checked='checked' ></td>";
		}
		else {
			print "<td><input type='radio' name='rowNumber' value='" . $rowCount . "'></td>";
		}
        print "<td>" . $row['message_id'] . "</td>";
        print "<td>" . $row['group_name'] . "</td>";
        print "<td>" . $row['user_name'] . "</td>";
		print "<td>" . $row['message'] . "</td>";
		print "<td>" . $row['retention_mode'] . "</td>";
		print "<td>" . $row['expiration_date'] . "</td>";
        print "</tr>";
		
		$rowCount = $rowCount + 1;
    }
    print "</table></form>";
	print "<button type='button' onClick='displaySelectedMessage()' >Show Message</button>";
	print "<button type='button' onClick='ajaxDeleteSelectedMessage();showGroupMessages();'>Delete Message</button>";

?>